<?php
namespace App\Logic\panel;

use Illuminate\Support\Facades\Cache;
use GuzzleHttp\Client;
use Illuminate\Support\Facades\DB;

class Panel
{
    public static function index()
    {
        $time = time();
        $time_use = $time-43200;

        $add_day = date('Y-m-d',$time_use);
        $yesterday = strtotime($add_day);

        $start_time = date('Y-m-d H:i:s',$yesterday);


        $today = $yesterday + 86400;

        $end_time = date('Y-m-d H:i:s',$today);


        $yesterday_use = $yesterday-43200;
        $zao = date('Y-m-d',$yesterday_use);

        //当日挖矿总容量
        $day_mining_capacity = DB::table('miner_host')
            ->where('start_time','<',$yesterday)
            ->where('end_time','>',$today)
            ->sum('hspace');

        //当日审核通过容量
        $day_check_capacity = DB::table('miner_host')
            ->where('add_time','>',$start_time)
            ->where('add_time','<',$end_time)
            ->sum('hspace');

        //当日挖矿总收益
        $day_mining = DB::table('miner_balance')
            ->where('timestamp','>',$start_time)
            ->where('timestamp','<',$end_time)
            ->where('type','mining')
            ->sum('amount');

        //当日总提现
        $day_withdraw_num = DB::table('withdraw')
            ->where('type','mb')
            ->where('token','FIL')
            ->where('check_time','>=',$start_time)
            ->where('check_time','<=',$end_time)
            ->sum('amount');

        //当日提现条数
        $day_withdraw_fil = DB::table('withdraw')
            ->where('type','mb')
            ->where('token','FIL')
            ->where('check_time','>=',$start_time)
            ->where('check_time','<=',$end_time)
            ->count();

        //当天的销售业绩
        $day_performance = DB::table('order')
            ->where('check_time','>',$start_time)
            ->where('status','=',1)
            ->sum('all_cny');

        //当天总的待提现
        $day_wait_withdraw = DB::table('miner_balance')
            ->where('token','FIL')
            ->sum('amount');



        $insert_arr = [

            'add_day' => $add_day,
            'mining_capacity' => $day_mining_capacity,
            'capacity' => $day_check_capacity,
            'mining' => $day_mining,
            'withdraw_num' => $day_withdraw_num,
            'withdraw_fil' => $day_withdraw_fil,
            'performance' => $day_performance,
            'wait_withdraw' => $day_wait_withdraw,


        ];

        $rel = DB::table('record_miner')->insert($insert_arr);
        return $rel;
    }


}





